package com.xue.qecode.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class InputUtils {

 public static List<String> readTxt(String filePath){
     try {
         ArrayList<String> strings = new ArrayList<>();
         File file = new File(filePath);

         if (file.isFile() && file.exists()){
             InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "utf-8");
             BufferedReader br = new BufferedReader(isr);
             String lineTxt = null;
             while ((lineTxt = br.readLine()) != null) {
//                 System.out.println(lineTxt);
                 strings.add(lineTxt);
             }
             if (strings.size()>0){
                 return strings;
             }
             br.close();
         }else {
             System.out.println("文件不存在");
         }
     }catch (Exception e){
         System.out.println("文件读取错误");
     }
     return null;
 }

}
